<!--订单列表-->
<h3>显示全部订单信息</h3>
<div id="orders_list">
	  <table>	
 	  <caption class="item_count">共有 <?php echo $item_count; ?> 条订单信息</caption>
		 <tr>
			 <th class="span-1">订单编号</th>
			 <th class="span-1">用户</th>
			 <th class="span-2">商品名称</th>
			 <th class="span-2">商品所属服务</th>
			 <th class="span-1">数量</th>
			 <th class="span-1">单价</th>
			 <th class="span-1">总价</th>
			 <th class="span-7">地址</th>
			 <th class="span-3">购买时间</th>
			 <th class="span-1">状态</th>
			 <th class="span-2">操作</th>
		</tr>
<?php
foreach( $orders as $no=>$order ){
?>
	 <tr> 
<td class="product_id hide"><?php echo $order['product_id']?></td>	 
<td class="user_id hide"><?php echo $order['user_id']?></td>	 
<td class="product_class_id hide"><?php echo $order['product_class_id']?></td>	 
		 <td class="align_center order_sn"><?php echo $order['order_sn']; ?></td>
		 <td class="align_center"><?php echo $order['user_nick']; ?></td>
		 <td class="align_left"><?php echo $order['product_title']; ?></td>
		 <td class="align_center"><?php echo $order['product_class_name_cn']; ?></td>
		 <td class="align_center quantity"><?php echo $order['quantity']; ?></td>
		 <td class="align_center price"><?php echo $order['price']; ?></td>
		 <td class="align_center sum_price"><?php echo $order['sum_price']; ?></td>
		 <td class="align_center address"><?php echo $order['address']; ?></td>
		 <td class="align_center time"><?php echo $order['time']; ?></td>
		 <td class="align_center status" ><?php echo $order['status']; ?></td>
		 <td class="align_center"><span class="button edit">修改</span><span class="button delete">删除</span></td>
	 </tr>
<?php
}
?>
	 </table>
</div>
<div id="pager_links"><?php echo $pager_links; ?></div>
<div id="dialog-confirm" title="" style="display:none;"></div>
<div id="dialog-form" title="" style="display:none;">
	<form>
	<fieldset>
		<input type="hidden" id="order_sn" name="order_sn" value="">
		<!--p>
			<label for="product_id">商品编号</label><br />
			<input type="text" name="product_id" id="product_id" class="text ui-widget-content ui-corner-all" />
		</p-->
		<!--p>
			<label for="product_class_id">所属服务编号</label><br />
			<input type="text" name="product_class_id" id="product_class_id" class="text ui-widget-content ui-corner-all" />
		</p-->
		<!--p>
			<label for="user_id">用户编号</label><br />
			<input type="text" name="user_id" id="user_id" class="text ui-widget-content ui-corner-all" />
		</p-->
		<p>
			<label for="quantity">购买数量</label><br />
			<input type="quantity" name="quantity" id="quantity" value="" class="text ui-widget-content ui-corner-all" />
		</p>
		<!--p>
			<label for="price">价格</label><br />
			<input type="price" name="price" id="price" value="" class="text ui-widget-content ui-corner-all" />
		</p-->
		<p>
			<label for="sum_price">总价</label><br />
			<input type="sum_price" name="sum_price" id="sum_price" value="" class="text ui-widget-content ui-corner-all" />
		</p>
		<p>
			<label for="address">收货地址</label><br />
			<input type="address" name="address" id="address" value="" class="text ui-widget-content ui-corner-all" />
		</p>
		<p>
			<label for="time">购买时间</label><br />
			<input type="time" name="time" id="time" value="" class="text ui-widget-content ui-corner-all" />
		</p>
		<p>
			<label for="status">状态</label><br />
			<select name="status" id="status">
				 <option value="BUY">购买</option>
				 <option value="PAID">已付款</option>
				 <option value="DISPATCH">已发货</option>
				 <option value="DONE">已完成</option>
				 <option value="ABANDON">取消</option>
			</select>
		</p>
	</fieldset>
	</form>
</div>


<script type="text/javascript">
//admin_order 
//{{{
//获取当前 tr 中的订单信息
//@param object this_button_el 当前点击的按钮对象
function get_order_info_in_this_tr( this_button_el ){
	 var this_tr_el = this_button_el.parent().parent();
	 var order_info = {};
	 order_info.order_sn = this_tr_el.find( '.order_sn' ).text();
	 order_info.product_id = this_tr_el.find( '.product_id' ).text();
	 order_info.user_id = this_tr_el.find( '.user_id' ).text();
	 order_info.product_class_id = this_tr_el.find( '.product_class_id' ).text();
	 order_info.price = this_tr_el.find( '.price' ).text();
	 order_info.sum_price = this_tr_el.find( '.sum_price' ).text();
	 order_info.quantity = this_tr_el.find( '.quantity' ).text();
	 order_info.address = this_tr_el.find( '.address' ).text();
	 order_info.status = this_tr_el.find( '.status' ).text();
	 order_info.time = this_tr_el.find( '.time' ).text();
	 return order_info;
}

var dialog_confirm_el = $( '#dialog-confirm' );
var dialog_form_el = $( '#dialog-form' );
//使能删除按钮
$( '.button' ).each( function( no , el ){
	 var this_button_el = $( el );
	 var this_tr_el = this_button_el.parent().parent();
	 if( this_button_el.hasClass( 'delete' ) ){
		 this_button_el.button({
			 icons: {
				 primary: "ui-icon-close"
			 },
			 text: false
		 });
		 this_button_el.click( function(){
			 dialog_confirm_el.dialog( "destroy" );
			 dialog_confirm_el.dialog({
				resizable: false,
				height:140,
				modal: true,
				title: "是否确认删除该订单?",
				buttons: {
					"确认删除": function(){
						 var this_order_info = get_order_info_in_this_tr( this_button_el );
						 $.post( '/admin/ajax_do_delete_order/' , { "order_sn":this_order_info.order_sn } , 
							 function( res ){
								 if( res.res == 'TRUE' ){
									 this_tr_el.fadeOut();
								 }else{
									 throw new Error( "删除订单失败" );
								 }
							 } , "json" );
						 $( this ).dialog( "close" );
					},
					"取消": function(){
						$( this ).dialog( "close" );
					}
				}
			 });
		 });
	 }
	 if( this_button_el.hasClass( 'edit' ) ){
		 this_button_el.button({
			 icons: {
				 primary: "ui-icon-gear"
			 },
			 text: false
		 });
		 this_button_el.click( function(){
			 var this_order_info = get_order_info_in_this_tr( this_button_el );
			 //初始化表单
			 var order_sn_el = $( '#order_sn' );
			 order_sn_el.val( this_order_info.order_sn );
			 //var product_id_el = $( '#product_id' );
			 //product_id_el.val( this_order_info.product_id );
			 //var user_id_el = $( '#user_id' );
			 //user_id_el.val( this_order_info.user_id );
			 //var product_class_id_el = $( '#product_class_id' );
			 //product_class_id_el.val( this_order_info.product_class_id );
			 var sum_price_el = $( '#sum_price' );
			 sum_price_el.val( this_order_info.sum_price );
			 var quantity_el = $( '#quantity' );
			 quantity_el.val( this_order_info.quantity );
			 var status_el = $( '#status' );
			 status_el.val( this_order_info.status );
			 var time_el = $( '#time' );
			 time_el.val( this_order_info.time );
			 var address_el = $( '#address' );
			 address_el.val( this_order_info.address );

			 dialog_form_el.dialog( "destroy" );
			 dialog_form_el.dialog({
				 height: 600,
				 width: 450,
				 modal: true,
				 buttons: {
					 "提交":function(){
						 //获取表单内容
						 $.post( '/admin/ajax_do_update_order/' , 
						 {
							 "order_sn":order_sn_el.val(), 
							 //"product_id":product_id_el.val(),
							 //"user_id":user_id_el.val(),
							 //"product_class_id":product_class_id_el.val(),
							 "sum_price":sum_price_el.val(),
							 "quantity":quantity_el.val(),
							 "status":status_el.val(),
							 "time":time_el.val(),
							 "address":address_el.val()
						 } , function( res ){	
							 if( res.res == "TRUE" ){
								 //更新订单列表内容
								 var this_tr = this_button_el.parent().parent();
								 //this_tr.find( '.product_id' ).text( product_id_el.val() );
								 //this_tr.find( '.user_id' ).text( user_id_el.val() );
								 //this_tr.find( '.product_class_id' ).text( product_class_id_el.val() );
								 this_tr.find( '.sum_price' ).text( sum_price_el.val() );
								 this_tr.find( '.quantity' ).text( quantity_el.val() );
								 this_tr.find( '.status' ).text( status_el.val() );
								 this_tr.find( '.time' ).text( time_el.val() );
								 this_tr.find( '.address' ).text( address_el.val() );
								 dialog_form_el.dialog( "destroy" );
							 }else{
								 throw new Error( "更新订单内容失败" );
							 }
						 } , "json" );
					 },
					 "取消":function(){
						 dialog_form_el.dialog( "destroy" );
					 }
				 }
			 });
		 });
	 }
});
//}}}
</script>

